package com.sdry.web.controller.cb;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.sdry.model.cb.Menu;
import com.sdry.model.jyy.Receive;
import com.sdry.service.cb.ReportJinService;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping("/ReportJin")
public class ReportJinController {

    public static Logger logger = LogManager.getLogger(ReportJinController.class);

    public static Map<String,Object> map = Collections.synchronizedMap(new HashMap<>());

    @Autowired
    private ReportJinService reportJinService;

    @RequestMapping()
    public String page() {
        return "/bb/jinKu";
    }

    /**
     *        {type:'numbers',title: '序号', width:80, sort: true, fixed: 'left'},
     *        {field: 'sendPhone', title: '供应商', width: 90},
     *        {field: 'receiveNumber', title: '单号', width:150},
     *        {field: 'sendName', title: 'QAD', width:160},
     *        {field: 'sendCompany', title: '物料名称', width: 277},
     *        {field: 'sendDate', title: '实际数量', width: 100},
     *        {field: 'createDate', title: '时间', width: 130},
     *        {field: 'remark', title: '备注', width: 180}];
     */
    @RequestMapping("/getMenu")
    @ResponseBody
    public String getMenu() {

        List<Menu> list = new ArrayList<>();

        Menu menu1 = new Menu();
        menu1.setField("");
        menu1.setTitle("序号");
        menu1.setWidth("80");
        list.add(menu1);
        Menu menu2 = new Menu();
        menu2.setField("sendPhone");
        menu2.setTitle("供应商");
        menu2.setWidth("90");
        list.add(menu2);
        Menu menu3 = new Menu();
        menu3.setField("sendName");
        menu3.setTitle("QAD");
        menu3.setWidth("160");
        list.add(menu3);
        Menu menu4 = new Menu();
        menu4.setField("sendCompany");
        menu4.setTitle("物料名称");
        menu4.setWidth("160");
        list.add(menu4);
        Menu menu5 = new Menu();
        menu5.setField("sendDate");
        menu5.setTitle("入库数量");
        menu5.setWidth("100");
        list.add(menu5);
        String date = "";
        List<Menu> list2 = reportJinService.getMenu(date);
        list.addAll(list2);

        Gson gson = new Gson();
        String s = gson.toJson(list);

        System.out.println(s);

        return s;
    }

    @RequestMapping("/getList")
    @ResponseBody
    public Map<String,Object> getList(
            String selectType,
            String selectTime, Integer page , Integer pageSize, String maName, String date,Long customer_id
    ) {
        logger.info("获取入库报表列表,page="+page+",pageSize="+pageSize+",ma_id="+maName+",date="+date);
        PageHelper.startPage(page,pageSize);
        List<Receive> list = reportJinService.getList(selectTime,maName,date,customer_id,selectType);
        PageInfo pageInfo = new PageInfo(list,5);
        map.put("code", 0);
        map.put("data", pageInfo.getList());
        map.put("count", pageInfo.getTotal());
        return map;
    }


}
